<template>
<view class="container">
	<view class="tip" v-if="cancel">
		注意：拒绝恶意接单，请详细填写您的原因，我们将核实接单情况，必要时与您联系取消原因！
	</view>
	<form @submit="formSubmit" @reset="formReset" report-submit="true">
		<view class="form-item">
			<text class="label" v-if="cancel">请输入原因：</text>
			<text class="label" v-else>退款原因</text>
			<view class="input-item"><textarea placeholder="如：等配件、改预约等" placeholder-style="color:#999;" name="reason"></textarea></view>
		</view>
		<view class="form-item" v-if="!cancel">
			<text class="label">退款金额(元)</text>
			<view class="flex"><input name="money" type="number" :value="totalprice" placeholder="请输入退款金额" placeholder-style="color:#999;"></input></view>
		</view>
		<button class="ref-btn" form-type="submit" :style="{background:t('color1')}">确定</button>
	</form>
	<loading v-if="loading"></loading>
	<dp-tabbar :opt="opt"></dp-tabbar>
	<popmsg ref="popmsg"></popmsg>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
			opt:{},
			loading:false,
      isload: false,
			menuindex:-1,

      orderid: '',
      totalprice: 0,
	  cancel: 0
    };
  },

  onLoad: function (opt) {
		this.opt = app.getopts(opt);
		this.getdata();
		var that = this;
		that.orderid = that.opt.orderid;
		that.totalprice = that.opt.price;
		that.cancel = that.opt.cancel;
  },
	onPullDownRefresh: function () {
		this.getdata();
	},

  methods: {
    formSubmit: function (e) {
      //console.log(e);return;
      var that = this;
      var orderid = that.orderid;
      var reason = e.detail.value.reason;
      var money = parseFloat(e.detail.value.money);

      if (reason == '') {
        app.alert('请填写原因');
        return;
      }

      // if (!that.cancel) {
      //   app.alert('退款金额有误');
      //   return;
      // }
			app.showLoading('提交中');
		if(that.cancel){
			app.post('ApiYuyue/cancel', {orderid: orderid,reason: reason}, function (data) {
				app.showLoading(false);
			  app.alert(data.msg);
			  if (data.status) {
				  setTimeout(function () {
				    app.goback(true);
				  }, 1000);
			  }
			  
			});
		}else{
			app.post('ApiYuyue/refund', {orderid: orderid,reason: reason,money: money}, function (data) {
			  app.showLoading(false);
			  app.alert(data.msg);
			  if (data.status) {
				  setTimeout(function () {
				    app.goback(true);
				  }, 1000);
			  }
			  
			});
		}
	  
    }
  }
};
</script>
<style>
.tip{color: red;}
.form-item{ width:100%;background: #fff; padding: 32rpx 20rpx;}
.form-item .label{ width:100%;height:60rpx;line-height:60rpx;font-weight: bold;}
.form-item .input-item{ width:100%;}
.form-item textarea{ width:100%;height:200rpx;border: 1px #eee solid;padding: 20rpx;}
.form-item input{ width:100%;border: 1px #eee solid;padding: 10rpx;height:80rpx}
.form-item .mid{ height:80rpx;line-height:80rpx;padding:0 20rpx;}
.ref-btn{ width: 90%; margin: 0 5%; height: 40px; line-height: 40px; text-align: center; color: #fff; font-size: 16px; border-radius: 8px;border: none; background: #ff8758; }
</style>